<template>
	<view>
    <uni-popup ref="inputDialog" type="dialog">
      <uni-popup-dialog ref="inputClose" mode="input" title="输入内容" value="对话框预置提示内容!" placeholder="请输入内容"
                        @confirm="dialogInputConfirm"></uni-popup-dialog>
    </uni-popup>

		<div class="container">
			<uni-grid :column="3" :show-border="false" :square="false">
				<uni-grid-item v-for="(item ,index) in list" :index="index" :key="index">
					<view class="grid-item-box" @tap="redirect(item.redirect)">
						<image class="image" :src="item.url" mode="aspectFill" />
						<text class="text">{{item.text}}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</div>
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		onShow(options) {
			// this.inputDialogToggle()
		},
		onLoad(options) {

			if (options.savemaitai == 1) {
				uni.showToast({
					title: '保存成功',
					duration: 1500
				});
			}
		},
		methods: {
			dialogInputConfirm(val) {
				if (val == '111111') {
					this.$refs.inputDialog.close()
				} else {
					uni.navigateBackMiniProgram({})
				}

			},
			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},
			redirect(url) {
				// uni.navigateTo({
				// 	//保留当前页面，跳转到应用内的某个页面
				// 	url: '/pages' + url
				// })
				if (url == '/savemaotai') {
					this.scan()
				} else {
					uni.navigateTo({
						//保留当前页面，跳转到应用内的某个页面
						url: '/pages' + url
					})
				}
			},
			scan() {
				uni.scanCode({
					success: (res) => {
						uni.showToast({
							title: '扫码成功',
							duration: 1500
						});
						this.redirect('/savemaotai?qrcode=' + res.result)
					},
					fail: (res) => {
						uni.showToast({
							title: '扫码失败',
							icon: 'error',
							duration: 1500
						});
					}
				})
			},
		},
		data() {
			return {
				messageText: '',
				msgType: 'err',
				list: [{
						redirect: '/savemaotai',
						url: '/static/save.png',
						text: '录入信息',
						type: "primary"
					},
					{
						redirect: '/findmaotai',
						url: '/static/list.png',
						text: '查询信息',
						type: "success"
					},
					{
						redirect: '/tumaotai',
						url: '/static/tumao.png',
						text: '联系方式',
						type: "error"
					},
					{
						redirect: '/savemaota21i',
						url: '/static/save.png',
						text: '录入信息',
						type: "primary"
					}
				]
			}
		}
	}
</script>

<style lang="scss">
	.container {
		margin-top: 25%;
		margin-bottom: 25%;
	}

	.image {
		width: 80px;
		height: 80px;
	}

	.text {
		font-size: 14px;
		margin-top: 5px;
	}

	.grid-item-box {
		flex: 1;
		// position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.grid-dot {
		position: absolute;
		top: 5px;
		right: 15px;
	}
</style>